import httplib
import urllib

class Http:
    __obj__ = False
    __method__ = "GET"
    __data__  = False
    __ssl__ = False
    __host__ = ""
    def __init__(self):
        Http.__method__  = "GET"
        Http.__data__  = False
        Http.__ssl__ = False
        Http.__obj__ = self
    @staticmethod
    def getInstance():
        if Http.__obj__:
            return Http.__obj__
        else:
            return Http()
    def setMethod(self, method):
        self.__method__ = method
        return Http.__obj__
    def SSL(self, model):
        self.__ssl__ = model
        return Http.__obj__
    def setData(self, data):
        self.__data__ = data
        return Http.__obj__
    def setHost(self,hosts):
        self.__host__ = hosts
        return Http.__obj__
    def Send(self,url):
        if self.__method__ == "GET":
          
            if(self.__data__):
                data = urllib.urlencode(self.__data__);
                data = "?"+data
            else:
                data = ""
            if self.__ssl__:
                ConnectionStr = url.replace("https://","")
                httpConnection = httplib.HTTPSConnection(self.__host__)
            else:
                ConnectionStr = url.replace("http://","")
                httpConnection = httplib.HTTPConnection(self.__host__)
            httpConnection.request(self.__method__, url+data)
        else:
            data = urllib.urlencode(self.__data__);
            if self.__ssl__:
                ConnectionStr = url.replace("https://","")
                httpConnection = httplib.HTTPSConnection(self.__host__)
            else:
                ConnectionStr = url.replace("http://","")
                httpConnection = httplib.HTTPConnection(self.__host__)
            headerdata = {
                      "Host":self.__host__,
                      "Content-Type":"application/x-www-form-urlencoded",
                      "Accept-Encoding":"gzip, deflate, br"
            }
            httpConnection.request(self.__method__, url, data, headerdata)
        return  httpConnection.getresponse()
        
